'''
将xlsx文件转换为json
目前暂时不支持内容替换
'''
from openpyxl import Workbook, load_workbook
import json

wb = load_workbook(filename='职工信息表.xlsx') # 这个需要我们设定

# 我们要设定表头, 我们应该从文件读入
head = [
        {
            'name': 'uid'
        },
        {
            'name': 'name'
        },
        {
            'skip': True,
        }
]

res = []

skip_first_row = True

ws = wb.active

for row in ws.iter_rows():
    if skip_first_row:
        skip_first_row = False
        continue

    new_insert = {}
    for i in range(len(head)):
        if head[i].get('skip', False):
            continue
        new_insert[head[i]['name']] = row[i].value
    res.append(new_insert)

print(json.dumps(res, indent=2, ensure_ascii=False))
